/*
 * 文件名： HttpUitl.java
 * 
 * 创建日期： 2010-2-22
 *
 * Copyright(C) 2010, chengguangming.
 *
 * 原始作者: <a href="mailto:chengguangming@fetionyy.com.cn">chengguangming</a>
 *
 */
package com.richdown.movie.util;

import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.sun.jersey.api.client.Client;
import com.sun.jersey.api.client.WebResource;

/**
 * http通用工具类
 * 
 * @author <a href="mailto:chengguangming@fetionyy.com.cn">chengguangming</a>
 * 
 * @version $Revision$
 * 
 * @since 2010-2-22
 * 
 * @see
 */
public class JerseyHttpClientUtil {
	private final static Logger logger = LoggerFactory.getLogger(JerseyHttpClientUtil.class);
	
	private static Client client=Client.create();

	public static String httpPost(String url, String content, String contentType)
			throws Exception {
		if(StringUtils.isBlank(contentType))
			contentType="application/x-www-form-urlencoded";
		String responseMessage = "";
		WebResource resource = client.resource(url);
		try {
			logger.info("发送报文：" + content);
			responseMessage = resource.type(contentType).post(String.class,
					content);
			logger.info("返回报文：" + responseMessage);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return responseMessage;
	}
    //get
	public static String httpGet(String url, String contentType)
			throws Exception {
		if(StringUtils.isBlank(contentType))
			contentType="application/x-www-form-urlencoded";
		String responseMessage = "";
		WebResource resource = client.resource(url);
		try {
			responseMessage = resource.type(contentType).get(String.class);
			logger.info("返回报文：" + responseMessage);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return responseMessage;
	}



}
